/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-05-14 11:47:59
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-14 18:06:03
 * @FilePath: /yt-devops/lib/pages/site/widgets/statistics_itme_widget.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'dart:core';

import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/format_util.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/styles/styles.dart';

///
/// @Description TODO
/// @Author liuer
/// @CreateTime 2024年03月27日 08:53
class StatisticsItemWidget extends StatelessWidget {
  final String title;
  final String numValue;
  final String unit;
  final String monetaryUnitName;
  final Color backgroundColor;
  final bool isHome;
  const StatisticsItemWidget(this.title, this.numValue, this.unit,this.monetaryUnitName,
  {this.backgroundColor = Colour.backgroundF5F5F7Color,
      this.isHome = true,
      super.key});

  @override
  Widget build(BuildContext context) {
    String realValue = '--';
    String unitStr = unit;
    if(monetaryUnitName.isNotEmpty && (unit == '元' || unit == '¥')){
      unitStr =  monetaryUnitName;
    }
    if (numValue != null && numValue.isNotEmpty && numValue != '--') {
      realValue = FormatUtil.commaSeparatedDigits(num.parse(numValue));

    }
    Log.d('numValue==' + numValue.toString());
    Log.d('unit==' + unit.toString());

    if (unit != null && numValue != '--' && (unit.toString() == '¥' || unit.toString() == '\$'||unit.toString() == '€') && num.parse(numValue) < 0) {
      unitStr = '-$unit';
      realValue = FormatUtil.commaSeparatedDigits(num.parse(numValue).abs());
    }

    return Container(
      // padding: EdgeInsets.only(left: 12.w,right: 12.w),
      height: isHome ? 72 : 68,
      width: isHome
          ? (ScreenUtil().screenWidth - 42.w - 32.w) / 2
          : (ScreenUtil().screenWidth - 42.w - 24.w) / 2,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10), color: backgroundColor),
      alignment: Alignment.center,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          isHome ? Gaps.vGap16 : Gaps.vGap12,
          (unitStr.contains('¥') ||unitStr.contains('€')
              ||unitStr.contains('\$'))
              ?Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(
                          text: unitStr,
                          style: ytTextStyle(
                            fontSize: 11,
                            color: Colour.mainTextColor,
                          )),
                      TextSpan(
                        text: realValue,
                        style: dinTextStyle(
                            fontSize: 18,
                            color: Colour.mainTextColor,
                            fontWeight: FontWeight.w500),
                      ),
                    ],
                  ),
                ): Text.rich(
            TextSpan(
              children: [
                TextSpan(
                  text: realValue,
                  style: dinTextStyle(
                      fontSize: 18,
                      color: Colour.mainTextColor,
                      fontWeight: FontWeight.w500),
                ),
                TextSpan(
                    text: unitStr,
                    style: ytTextStyle(
                      fontSize: 11,
                      color: Colour.mainTextColor,
                    )),
              ],
            ),
          ),
          Gaps.vGap4,
          Text(
            title,
            textAlign: TextAlign.center,
            style: ytTextStyle(
                fontSize: 12,
                color: Colour.labelTextColor,
                fontWeight: FontWeight.normal),
          ),
        ],
      ),
    );
  }
}
